import json
from typing import Any

from fastapi import FastAPI, Header

app = FastAPI()


@app.get("/esb/produce")
@app.post("/esb/produce")
async def bird(authorization: str = Header(None)) -> Any:
    if authorization:
        print(authorization)  # UlQ6UlRfUA==
    with open("./bird.json", "r", encoding="UTF-8") as __file:
        data = json.loads(__file.read())
    return "ZCZC " + json.dumps(data) + " NNNN"


@app.post("/esb/keepalive")
async def keepalive(authorization: str = Header(None), endpoint: str = Header(None),
                    clientmac: str = Header(None)) -> Any:
    if authorization:
        print(f"authorization: {authorization}")  # UlQ6UlRfUA==
    if endpoint:
        print(f"endpoint: {endpoint}")
    if clientmac:
        print(f"clientmac: {clientmac}")
    with open("./keepalive.json", "r", encoding="UTF-8") as __file:
        data = json.loads(__file.read())
    return "ZCZC " + json.dumps(data) + " NNNN"


@app.get("/fod")
async def fod(authorization: str = Header(None)) -> Any:
    with open("FOD.json", "r", encoding="UTF-8") as __file:
        data = json.loads(__file.read())

    return data


if __name__ == "__main__":
    import uvicorn

    uvicorn.run("HTTPS:app", port=8081, reload=True, host="0.0.0.0")
